<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header('工作记录列表')"></head>
<link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input id="deptId" name="deptId" type="hidden"/>
                    <ul>
                        <li id="dept">
                            <label>部门名称：</label>
                            <input type="text" onclick="selectDeptTree()" id="deptName" name="deptName" autocomplete="off"/>
                        </li>
                        <li id="user">
                            销售名称：<input type="text" name="userName"/>
                        </li>
                        <li>
                            客户名称：<input type="text" name="customerName"/>
                        </li>
                        <li>
                            新老客户：<select id="isNew" name="isNew">
                                        <option value="">请选择</option>
                                        <option value="新客户">新客户</option>
                                        <option value="老客户">老客户</option>
                                    </select>
                        </li>
                        <li>
                        工作类型：
                        <select id="workType" name="workType">
                            <option value="">请选择</option>
                            <option value="0">电话联系</option>
                            <option value="1">实地拜访</option>
                            <option value="2">提交方案</option>
                            <option value="3">合同签约</option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>时间区间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime" autocomplete="off"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime" autocomplete="off"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="crm:work:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="crm:work:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="crm:work:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:work:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('crm:crmWorkRecord:edit')}]];
    var removeFlag = [[${@permission.hasPermi('crm:crmWorkRecord:remove')}]];
    var prefix = ctx + "crm/work";
    var roleKey = [[${roleKey}]];

    function checkRole(role) {
        if (role.indexOf('manager')) {
            $("#dept").show();
        } else if (role.indexOf('employee')) {
            $("#dept").hide();
            $("#user").hide();
        } else {
            $("#dept").show();
        }
    }

    $(function () {
        // 检测角色
        checkRole(roleKey);

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/workExport",
            modalName: "工作记录",
            search: false,
            showExport: false,
            columns: [{
                checkbox: true
            },
                {
                    field: 'workId',
                    title: '工作记录id',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '员工姓名',
                    sortable: true
                },
                {
                    field: 'customerName',
                    title: '客户名称',
                    sortable: true
                },
                {
                    field: 'isNew',
                    title: '是否新客户',
                    sortable: true
                },
                {
                    field: 'workType',
                    title: '工作类型',
                    sortable: true,
                    formatter: function (value, row, index) {
                            switch (value) {
                                case 0 : return "电话联系";
                                case 1 : return "拜访客户";
                                case 2 : return "提交方案";
                                case 3 : return "合同签约";
                            }
                        }
                },
                {
                    field: 'startTime',
                    title: '工作开始时间',
                    sortable: true
                },
                {
                    field: 'endTime',
                    title: '工作结束时间',
                    sortable: true,
                    visible : false
                },
                {
                    field: 'item',
                    title: '事项',
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    sortable: true
                },
                {
                    field: 'address',
                    title: '地址',
                    sortable:
                        true
                },
                {
                    field: 'createUser',
                    title: '创建人',
                    sortable:  true
                }
                ,
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.workId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.workId + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                }
            ]
        };
        $.table.init(options);
    });
</script>
</body>
</html>